package com.example.demo.config;


import com.example.demo.common.AppVariable;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptort())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/blog_list.html")
                .excludePathPatterns("/blog_content.html")
                .excludePathPatterns("/art/detail")
                .excludePathPatterns("/art/incr-rcount")
                .excludePathPatterns("/user/getuserbyid")
                .excludePathPatterns("/art/listbypage")
                .excludePathPatterns("/art/searchblog")
                .excludePathPatterns("/art/timeadd")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/user/getcode")
                .excludePathPatterns("/update_secret.html")
                .excludePathPatterns("/user/initques")
                .excludePathPatterns("/excessive.html")
                .excludePathPatterns("/user/checkuser")
                .excludePathPatterns("/user/juganswer")
                .excludePathPatterns("/comment/show")
                .excludePathPatterns("/comment/add")
                .excludePathPatterns("/comment/del")
                .excludePathPatterns("/user/updatesecret")
                .excludePathPatterns("/secret_update.html")
                .excludePathPatterns("/img/photo/**");
    }

    /**
     *  静态资源映射
     *  这段代码是Java Spring框架中用来配置静态资源访问的部分。
     *  它的作用是将"/photo/**"路径下的请求映射到文件系统中的特定位置，
     *  也就是将这个路径下的请求映射到指定的上传文件路径。
     *  具体来说，它告诉应用程序在处理类似"/photo/abc.jpg"这样的请求时，到指定的文件系统路径下查找对应的资源并返回给用户。
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/photo/**")
                .addResourceLocations("file:///"+ AppVariable.UPLOADS_PATH);
    }

}
